/*请尝试用filter()筛选出素数：*/

'use strict';

function get_primes(arr) {

    r = arr.filter(function (s) {

        var result = true;
        if (s === 1) {
            result = false;
        }

        for (let i = 2; i < s; i++) {

            if (s % i === 0) {

                result = false;

            }

        }

        return result;
    }
    )
    return r;
}

// 测试:
var
    x,
    r,
    arr = [];
for (x = 1; x < 100; x++) {
    arr.push(x);
}

r = get_primes(arr);

if (r.toString() === [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97].toString()) {
    console.log('测试通过!');
} else {
    console.log('测试失败: ' + r.toString());
}